<template>
  <div class="tab">
    <ul>
      <!-- :class="cur === ind ? 'active': '' " -->
      <!-- :class='["active",cur==ind ? "active" : ""]' -->
      <li
        v-for="(item,ind) in this.arr"
        :key="ind"
        :class="{active:cur===ind}"
        @click="_handleClick(item,ind)"
      >{{item}}</li>
    </ul>
    <div class="content">
      <!-- <router-view/> -->
      <component :is="name"></component>
      <!-- {{this.arrcontent[cur]}} -->
      <!-- {{cur}} -->
    </div>
  </div>
</template>
<script>
// import aa from './aa'
// import bb from './bb'
// import cc from './cc'

export default {
  // 1.接收到子组件传过来的数据
  props: ['arrcontent', 'arr'],
  data() {
    return {
      // cur是当前显示的tabs的标题
      cur: 0,
      list: [],
      name: 'aa'
    }
  },
  created() {
    // for (let i = 0; i < this.arrcontent.length; i++) {
    //   this.list.push({ template: '<div>' + this.arrcontent[i] + '</div>' })
    // }
  },
  methods: {
    _handleClick(item, ind) {
      this.cur = ind
      this.name = item
    }
  }
}
</script>
<style scoped>
ul {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
li {
  width: 100px;
  text-align: center;
  float: left;
}
.active {
  background: skyblue;
  color: white;
}
.content {
  width: 300px;
  height: 250px;
  background: salmon;
}
.tab {
  overflow: hidden;
}
</style>
